package com.soonfor.evaluate.view;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;


import com.estronger.shopmanage.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * author: DC-DingYG on 2018-11-15 14:18
 * e-mail: dingyg012655@126.com
 */
public class SelectLinearView extends LinearLayout {

    private Context mContext;
    @BindView(R.id.llfGoodEvalV)
    LinearLayout llfGoodEvalV;
    @BindView(R.id.llfMiddleEvalV)
    LinearLayout llfMiddleEvalV;
    @BindView(R.id.llfBadEvalV)
    LinearLayout llfBadEvalV;
    @BindView(R.id.img_g1)
    ImageView img_g1;
    @BindView(R.id.img_m2)
    ImageView img_m2;
    @BindView(R.id.img_b3)
    ImageView img_b3;
    private onCheckListener listener;

    public SelectLinearView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        View view = View.inflate(context, R.layout.view_selectradiobutton, this);
        ButterKnife.bind(this, view);
    }

    /**
     * editable
     *
     * @param mContext
     */
    public void initSelectLinearView(final Activity mContext, int selectId, onCheckListener listener) {
        this.mContext = mContext;
        this.listener = listener;
        showView(selectId);
        setListener();
    }

    private void showView(int selectId) {
        switch (selectId) {
            case 1:
                img_g1.setSelected(true);
                img_m2.setSelected(false);
                img_b3.setSelected(false);
                break;
            case 2:
                img_g1.setSelected(false);
                img_m2.setSelected(true);
                img_b3.setSelected(false);
                break;
            case 3:
                img_g1.setSelected(false);
                img_m2.setSelected(false);
                img_b3.setSelected(true);
                break;
            default:
                img_g1.setSelected(false);
                img_m2.setSelected(false);
                img_b3.setSelected(false);
                break;
        }
    }

    private void setListener(){
        llfGoodEvalV.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                showView(1);
                if(listener!=null) listener.select(1, "好评");
            }
        });
        llfMiddleEvalV.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                showView(2);
                if(listener!=null) listener.select(2, "中评");
            }
        });
        llfBadEvalV.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                showView(3);
                if(listener!=null) listener.select(3, "差评");
            }
        });
    }

    public interface onCheckListener{
        void select(int selectId, String stext);
    }

}
